package com.example.widgetcase.slice.subject;

import com.example.widget_lib.callback.ScrollObserver;
import com.example.widget_lib.callback.ScrollSubject;

import java.util.ArrayList;
import java.util.List;

public class ScrollSubscription implements ScrollSubject {
    //储存订阅公众号的微信用户
    private List<ScrollObserver> weixinUserlist = new ArrayList<>();

    @Override
    public void attach(ScrollObserver observer) {
        weixinUserlist.add(observer);
    }

    @Override
    public void detach(ScrollObserver observer) {
        weixinUserlist.remove(observer);
    }

    @Override
    public void notify(int currScrollX, int currScrollY) {
        for (ScrollObserver observer : weixinUserlist) {
            observer.updateScroll(currScrollX, currScrollY);
        }
    }
}
